home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / IIGS / TN.IIGS.037 < prev    next >
Encoding:
Text File  |  1989-04-22  |  8.8 KB  |  180 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple IIGS
  8. #37:    Free-Form Synthesizer Tips
  9.  
  10. Revised by:    Jim Mensch                                       November 1988
  11. Written by:    Jim Mensch                                            May 1988
  12.  
  13. This Technical Note is intended to help a person who is unfamiliar with the 
  14. Apple IIGS Sound Tool Set use the Free-Form Synthesizer effectively.
  15. _____________________________________________________________________________
  16.  
  17. The primary function of the Free-Form Synthesizer is to allow an application 
  18. program to start one or more complex digitized or computed waveforms playing 
  19. on the Apple IIGS without further intervention from the application.  The 
  20. waveform is a series of bytes, each representing the amplitude of your 
  21. outgoing sound at a particular moment in time (defined by the sampling 
  22. frequency you set).  After a call to FFStartSound, the Sound Tool Set takes 
  23. care of all chores involved in loading the DOC RAM, setting up registers, and 
  24. actually playing your sound.  Once playing, your sound will continue until 
  25. either the Sound Tool Set encounters a NIL pointer in the waveform list, or 
  26. until you call FFStopSound.
  27.  
  28.  
  29. FFStartSound Parameters
  30.  
  31. FFStartSound has only two parameters:  the first a Word containing channel, 
  32. generator, and mode information, and the second a Pointer to a parameter 
  33. block.
  34.  
  35.       |15 |14 |13 |12 |11 |10| 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  36.         |___________|   |__________|   |___________|   |___________|
  37.               |              |               |               |
  38.               |              |               |               |
  39. DOC channel number ($0-$1)   |   Reserved must be set to 0   |
  40. top 3 bits should be set to 0|                               |
  41.                              |                  Free-Form Synthesizer = $01     
  42.                  Generator number ($0-$E)            Note Synthesizer = $02
  43.                                                          Reserved = $03-$07
  44.                                               Application defined = $08-$0F
  45.                                                                                       
  46.                     Figure 1 - Channel-Generator-Mode Word
  47.  
  48. The Channel-Generator-Mode Word is broken down into 4 nibbles.  The low-order 
  49. nibble specifies the particular synthesizer you are using.  (Because this Note 
  50. is only about the Free-Form Synthesizer, we will be using only a 1 in this 
  51. nibble.)  The adjacent nibble must be set to 0 for now.  The next nibble 
  52. specifies which generator to use.  The IIGS has 15 generators from which to 
  53. choose, and as the application designer, it is up to you to decide which one 
  54. to use.  It might be appropriate, however, to call FFGeneratorStatus first to 
  55. ensure that the generator currently is available.  (It could be in use already 
  56. by a desk accessory or previously started sound.)  The high-order nibble 
  57. specifies which channel to use.  The IIGS supports two separate sound channels 
  58. for output.  If you are using a stereo adapter, you could start up many sounds 
  59. and route them to either channel 0 or channel 1 to get a full stereo effect.  
  60. (The channel is ignored if you are not using a special piece of multi-channel 
  61. hardware.)
  62.  
  63. The parameter block contains parameters describing the sound and how it should 
  64. be played.  Here is a sample Pascal definition of that parameter block:
  65.  
  66.     FFParmBlock = record
  67.                   waveStart:Ptr;
  68.                   waveSize:Integer;
  69.                   freqOffset:Integer;
  70.                   DOCBuffer:Integer;     { High order byte significant }
  71.                   bufferSize:Integer;    { Low order byte significant }
  72.                   nextWave:^FFParmBlock;
  73.                   volSetting:Integer;
  74.                  end;
  75.  
  76. The first parameter is a 4-byte address telling the Free-Form Synthesizer 
  77. where in memory it can locate your sample data.  The next parameter is a word 
  78. specifying the number of 256-byte pages of sound you wish to play.  The 
  79. waveform data should be a series of bytes, each representing one sample.  Wave 
  80. tables must be exact multiples of 256 bytes.
  81.  
  82. Note:    A zero value in the waveform can cause a sound to stop, so 
  83. be sure to check your data to ensure that this does not happen.
  84.  
  85. The frequency offset parameter specifies the sampling frequency that the Free-
  86. Form Synthesizer should use during playback.  This number can be computed by 
  87. the following formula:
  88.  
  89.               freqOffset = ((32*Sample rate in Hertz)/1645)
  90.  
  91. The frequency offset parameter is the most often misunderstood parameter, so I 
  92. will explain a little about sampling rates.  The sampling rate is how many 
  93. samples (bytes) per second to play.  If you have a digitized wave that 
  94. represents 2 seconds of sound, and it takes up 44K of memory, then it was 
  95. sampled at 22 kHz (which, by the way, is good for full sound reproduction).  
  96. The sampling rate must be at least twice that of the maximum fundamental 
  97. frequency you want to sample.  However, for good sound reproduction, you may 
  98. want to sample at least eight times the fundamental frequency in order to 
  99. capture the higher harmonics of musical instruments and the human voice.
  100.  
  101. The DOC starting address and buffer size tell the Free-Form Synthesizer which 
  102. portion of the 64K sound RAM to use as a buffer during playback.  The wave is 
  103. taken from your waveform in chunks and placed in sound RAM for playback.  Each 
  104. time the buffer nears empty, it will need to be reloaded with more sound.  The 
  105. size of the buffer specified determines how often the Free-Form Synthesizer 
  106. must interrupt the 65816 to reload the buffer.  The buffer size must be a 
  107. power of two because of the way the sound General Logic Unit (GLU) specifies 
  108. addresses.  (The value for this parameter must also be a power of two.)  A 
  109. good length to use would be at least 1/10 second of sound.  For example, if 
  110. you were using a sampling rate of 16 kHz (16,000 samples per second), you 
  111. would want a buffer at least 2,048 bytes long, or about 8 pages.  It does not 
  112. hurt to round this number up.  You manage the DOC RAM, so you should decide 
  113. what memory to use.  It is usually a good idea to have multiple buffers if you 
  114. have a chain of waves.  (I like leaving page zero free, as the Note 
  115. Synthesizer uses the data in the first 256 bytes, and accidentally placing a 
  116. zero in that page could cause it to fail.)
  117.  
  118. The next wave pointer is a 4-byte pointer to the next parameter block.  With 
  119. this parameter you can string together many waveforms for more continuous 
  120. sound, or you can make your sounds infinitely recursive by pointing back to 
  121. the original wave form.
  122.  
  123. The volume setting is a word which represents the relative playback volume.  
  124. It can range from 0 to 255.
  125.  
  126.  
  127. Other Tips
  128.  
  129. When you shut down the Sound Tool Set, it will stop all pending sounds, so be 
  130. sure to leave ample time between starting and ending a sound.  If you have a 
  131. series of wave forms strung together, you can change their parameters on the 
  132. fly.  Changes take effect as soon as the waveform is started.  (You could use 
  133. this to find the correct sampling frequency of a wave, by having the next wave 
  134. pointer point back to the start of your parameter block.  This would cause the 
  135. sound to play indefinitely.  You then could change the freqOffset value, and 
  136. the sound would change each time it is restarted.)
  137.  
  138. Here is a sample code segment (in APW Assembler format) that creates a 1-kHz 
  139. wave in memory sampled at 16 kHz and plays it:
  140.  
  141. FFSound       DATA
  142.  
  143. theSound      ds    $2000           ; FFSound wave...
  144. MyFFRecord    dc    A4'theSound'    ; address of wave
  145.               dc    i'$20'          ; size of wave in pages..
  146. Rate          dc    i'311'          ; 16-kHz sample rate
  147.               dc    i'1'            ; DOC starting address
  148.               dc    i'$0800'        ; DOC buffer size
  149.               dc    a4'0'           ; no next wave
  150. Vol1          dc    i'$007F'        ; kinda medium..
  151.  
  152. ; 1-kHz triangle wave sampled at 16 kHz one full segment
  153. oneAngle      dc    i1'$40,$50,$60,$70,$80,$90,$A0,$B0'
  154.               dc    i1'$C0,$B0,$A0,$90,$80,$70,$60,$50'
  155.               End
  156.  
  157. TestFF        Start
  158.               Using    FFSound
  159. MakeWave      ANop
  160.               ldx    #$0000
  161. MW0010        txa                   ; get index
  162.               and    #$000F         ; use just low nibble as index
  163.               tay                   ; into triangle wave table
  164.               lda    oneAngle,y     ;
  165.               sta    theSound,X     ; and store it into sound buf
  166.               inx
  167.               inx
  168.               cpx    #$2000         ; we Done?
  169.               blt    MW0010         ; nope better finish
  170.               PushWord     #$0001
  171.               PushLong     #MyFFRecord
  172.               _FFStartSound
  173.               rts
  174.               end
  175.  
  176.  
  177. Further Reference
  178.     o    Apple IIGS Toolbox Reference, Volume 2
  179.  
  180.